package com.ruoyi.laiqianba.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.db.mapper.AddressInfoMapper;
import com.ruoyi.db.domain.AddressInfo;
import com.ruoyi.laiqianba.service.IAddressInfoService;

/**
 * 地址列表Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-08-13
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class AddressInfoServiceImpl implements IAddressInfoService 
{
    @Autowired
    private AddressInfoMapper addressInfoMapper;

    /**
     * 查询地址列表
     * 
     * @param cityCode 地址列表主键
     * @return 地址列表
     */
    @Override
    public AddressInfo selectAddressInfoByCityCode(String cityCode)
    {
        return addressInfoMapper.selectAddressInfoByCityCode(cityCode);
    }

    /**
     * 查询地址列表列表
     * 
     * @param addressInfo 地址列表
     * @return 地址列表
     */
    @Override
    public List<AddressInfo> selectAddressInfoList(AddressInfo addressInfo)
    {
        return addressInfoMapper.selectAddressInfoList(addressInfo);
    }

    /**
     * 新增地址列表
     * 
     * @param addressInfo 地址列表
     * @return 结果
     */
    @Override
    public int insertAddressInfo(AddressInfo addressInfo)
    {
        return addressInfoMapper.insertAddressInfo(addressInfo);
    }

    /**
     * 修改地址列表
     * 
     * @param addressInfo 地址列表
     * @return 结果
     */
    @Override
    public int updateAddressInfo(AddressInfo addressInfo)
    {
        return addressInfoMapper.updateAddressInfo(addressInfo);
    }

    /**
     * 批量删除地址列表
     * 
     * @param cityCodes 需要删除的地址列表主键
     * @return 结果
     */
    @Override
    public int deleteAddressInfoByCityCodes(String[] cityCodes)
    {
        return addressInfoMapper.deleteAddressInfoByCityCodes(cityCodes);
    }

    /**
     * 删除地址列表信息
     * 
     * @param cityCode 地址列表主键
     * @return 结果
     */
    @Override
    public int deleteAddressInfoByCityCode(String cityCode)
    {
        return addressInfoMapper.deleteAddressInfoByCityCode(cityCode);
    }

    @Override
    public Map<String, List<Map<String, String>>> selectCodeAndCity() {
        List<Map<String, String>> cityList = addressInfoMapper.selectCodeAndCity();

        Map<String, List<Map<String, String>>> groupedData = new HashMap<>();

        for (Map<String, String> cityInfo : cityList) {
            String province = cityInfo.get("province");
            if (!groupedData.containsKey(province)) {
                groupedData.put(province, new ArrayList<>());
            }
            groupedData.get(province).add(cityInfo);
        }

        return groupedData;
    }

    @Override
    public List<Map<String, String>> getCtiy() {
        return addressInfoMapper.getCtiy();
    }

    @Override
    public List<Map<String, Object>> getProvinceAll() {
        return addressInfoMapper.getProvinceAll();
    }
}
